package com.cyt.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cyt.dao.impl.LiuYanDaoImpl;
import com.cyt.entity.LiuYan;
import com.cyt.util.DateTime;
import com.cyt.util.Result;

import javafx.scene.Parent;


//留言板
public class MessageServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//接受前台传来的参数
		String lYName = request.getParameter("lYName");
		String lYDianHua = request.getParameter("lYDianHua");
		String lYYouXiang = request.getParameter("lYYouXiang");
		String lYNeiRong = request.getParameter("lYNeiRong");
		Date date=new Date();
		String shiJian=DateTime.getStringTime(date);
		String getZhuangtai = request.getParameter("未读");

		LiuYan liuYan=new LiuYan(lYName, lYDianHua, lYYouXiang, lYNeiRong, 0, shiJian,getZhuangtai,null);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out =response.getWriter();
		//实现类
		LiuYanDaoImpl lyDao=new LiuYanDaoImpl();
		int n= lyDao.addLiuYan(liuYan);//获得受影响行数
		if(n>0) {//成功
			out.print(Result.toClient(true, "留言成功", "感谢您的宝贵意见,祝您生活愉快!!"));
			
		}else {//失败
			out.print(Result.toClient(false, "留言失败", "服务器开了小差哦,请您重新留言,谢谢!"));

		}
		
		out.flush();
		out.close();
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
